define(['jquery', 'bootstrap', 'backend', 'table', 'form'], function ($, undefined, Backend, Table, Form) {

    var Controller = {
        index: function () {
            // 初始化表格参数配置
            Table.api.init({
                extend: {
                    index_url: 'order/index' + location.search,
                    add_url: 'order/add',
                    edit_url: 'order/edit',
                    del_url: 'order/del',
                    multi_url: 'order/multi',
                    import_url: 'order/import',
                    table: 'order',
                }
            });

            var table = $("#table");

            // 初始化表格
            table.bootstrapTable({
                url: $.fn.bootstrapTable.defaults.extend.index_url,
                pk: 'id',
                sortName: 'id',
                exportTypes: ['excel'],
                columns: [
                    [
                        {checkbox: true},
                        {field: 'no',
                         title: __('编号'),
                           sortable: true,
                           operate:false,
                           align: "center",
                           width: 40,
                           formatter: function (value, row, index) {
                               //获取每页显示的数量
                               var pageSize=table.bootstrapTable('getOptions').pageSize;
                               //获取当前是第几页
                               var pageNumber=table.bootstrapTable('getOptions').pageNumber;
                               //返回序号，注意index是从0开始的，所以要加上1
                               return pageSize * (pageNumber - 1) + index + 1;
                           }
                        }, 
                        // {field: 'id', title: __('Id'),operate: false},
                        {field: 'userName', title: __('Username')},
                        {field: 'safe_years', title: __('Safe_years'),operate: false},
                        {field: 'insurance_company', title: '保险公司', searchList: {"PINGAN":'中国平安保险',"PICC":'中国人民财产保险'}, formatter: function (value,row) {
                            if (value === 'PINGAN') return '中国平安保险';
                            if (value === 'PICC') return '中国人民财产保险';
                         }},
                        {field: 'big_number', title: __('Big_number')},
                        {field: 'small_number', title: __('Small_number')},
                        {field: 'fee', title: __('Fee'),operate: false},
                        {field: 'email', title: '电子邮箱',operate: false},
                        // {field: 'invite_name', title: __('Invite_name'),operate: false},
                        {field: 'car_style', title: __('Car_style'),operate: false},
                        {field: 'real_name', title: __('Real_name')},
                        {field: 'card_no', title: __('Card_no')},
                        {field: 'tel', title: __('Tel')},
                        {field: 'card_address', title: __('Card_address'),operate: false},
                        {field: 'address', title: __('Address'),operate: false},
                        {field: 'car_number', title: __('Car_number')},
                        {field: 'vehicle_model', title: __('Vehicle_model'),operate: false},
                        {field: 'car_no', title: __('Car_no'),operate: false},
                        {field: 'engine_number', title: __('Engine_number'),operate: false},
                        {field: 'frame_number', title: __('Frame_number'),operate: false},
                        {field: 'dj_time', title: __('Dj_time'), operate:'RANGE', addclass:'datetimerange', formatter: Table.api.formatter.datetime,datetimeFormat:'YYYY-MM-DD',operate: false},
                        {field: 'buy_time', title: __('Buy_time'), operate:'RANGE', addclass:'datetimerange', formatter: Table.api.formatter.datetime,datetimeFormat:'YYYY-MM-DD',operate: false},
                        {field: 'az_address', title: __('Az_address'),operate: false},
                        // {field: 'az_user', title: __('Az_user'),operate: false},
                        {field: 'device_id', title: __('Device_id'),operate: false},
                        {field: 'car_price', title: __('Car_price'),operate: false},
                        {field: 'dk_prrice', title: __('Dk_prrice'),operate: false},
                        {field: 'beneficiary', title: __('Beneficiary'),operate: false},
                        {field: 'create_time', title: __('Create_time'), operate:'RANGE', addclass:'datetimerange', formatter: Table.api.formatter.datetime,operate: false},
                        {field: 'out_trade_no', title: __('Out_trade_no'),operate: false},
                        {field: 'pay_status', title: __('Pay_status'),operate: false},
                        {field: 'pay_time', title: __('Pay_time'), operate:'RANGE', addclass:'datetimerange', formatter: Table.api.formatter.datetime,operate: false},
                        // {field: 'recipient_name', title: __('Recipient_name'),operate: false},
                        {field: 'operate', title: __('Operate'), table: table,buttons: [
                                    {name: 'nullify', title: '作废', icon: 'fa fa-paper-plane', classname: 'btn btn-xs btn-primary btn-magic btn-ajax',
                                    //按钮其他属性
                                    hidden:function(value,row){
                                        if(value.authId == '1'){ 
                                          return false; //或者return false
                                        }
                                        if(value.differ >= '72'){
                                          return true; //或者return false
                                        } 
                                    }, 
                                    url: 'order/nullify',confirm: '确认作废?',
                                    success: function (data, ret) {
                                        $(".btn-refresh").trigger("click");
                                        // Layer.alert('操作成功');
                                        //如果需要阻止成功提示，则必须使用return false;
                                        return false;
                                    },
                                    error: function (data, ret) {
                                        console.log(data, ret);
                                        Layer.alert(ret.msg);
                                        return false;
                                    }
                                }
                                ],events: Table.api.events.operate, formatter: Table.api.formatter.operate}
                    ]
                ],exportOptions: { 
                  mso:{  
                    onMsoNumberFormat: function (cell, row, col) {
                        return !isNaN($(cell).text())?'\\@':'';
                    },
                  }
                },
            });

            // 为表格绑定事件
            Table.api.bindevent(table);
        },
        nullifylist: function () {
            // 初始化表格参数配置
            Table.api.init({
                extend: {
                    index_url: 'order/nullifylist' + location.search, 
                    add_url: 'order/add',
                    edit_url: 'order/edit',
                    del_url: 'order/del',
                    multi_url: 'order/multi',
                    import_url: 'order/import',
                    table: 'order',
                    table: 'order',
                }
            });

            var table = $("#table");

            // 初始化表格
            table.bootstrapTable({
                url: $.fn.bootstrapTable.defaults.extend.index_url,
                pk: 'id',
                sortName: 'id',
                exportTypes: ['excel'],
                columns: [
                    [
                        {checkbox: true},
                        {field: 'no',
                         title: __('编号'),
                           sortable: true,
                           operate:false,
                           align: "center",
                           width: 40,
                           formatter: function (value, row, index) {
                               //获取每页显示的数量
                               var pageSize=table.bootstrapTable('getOptions').pageSize;
                               //获取当前是第几页
                               var pageNumber=table.bootstrapTable('getOptions').pageNumber;
                               //返回序号，注意index是从0开始的，所以要加上1
                               return pageSize * (pageNumber - 1) + index + 1;
                           }
                        }, 
                        // {field: 'id', title: __('Id'),operate: false},
                        {field: 'userName', title: __('Username')},
                        {field: 'safe_years', title: __('Safe_years'),operate: false},
                       	{field: 'insurance_company', title: '保险公司11', searchList: {"PINGAN":'中国平安保险',"PICC":'中国人民财产保险'}, formatter: function (value,row) {
                            if (value === 'PINGAN') return '中国平安保险';
                            if (value === 'PICC') return '中国人民财产保险';
                         }},
                        {field: 'big_number', title: __('Big_number')},
                        {field: 'small_number', title: __('Small_number')},
                        {field: 'fee', title: __('Fee'),operate: false},
                        // {field: 'invite_name', title: __('Invite_name'),operate: false},
                        {field: 'car_style', title: __('Car_style'),operate: false},
                        {field: 'real_name', title: __('Real_name')},
                        {field: 'card_no', title: __('Card_no')},
                        {field: 'tel', title: __('Tel')},
                        {field: 'card_address', title: __('Card_address'),operate: false},
                        {field: 'address', title: __('Address'),operate: false},
                        {field: 'car_number', title: __('Car_number')},
                        {field: 'vehicle_model', title: __('Vehicle_model'),operate: false},
                        {field: 'car_no', title: __('Car_no'),operate: false},
                        {field: 'engine_number', title: __('Engine_number'),operate: false},
                        {field: 'frame_number', title: __('Frame_number'),operate: false},
                        {field: 'dj_time', title: __('Dj_time'), operate:'RANGE', addclass:'datetimerange', formatter: Table.api.formatter.datetime,datetimeFormat:'YYYY-MM-DD',operate: false},
                        {field: 'buy_time', title: __('Buy_time'), operate:'RANGE', addclass:'datetimerange', formatter: Table.api.formatter.datetime,datetimeFormat:'YYYY-MM-DD',operate: false},
                        {field: 'az_address', title: __('Az_address'),operate: false},
                        {field: 'az_user', title: __('Az_user'),operate: false},
                        {field: 'device_id', title: __('Device_id'),operate: false},
                        {field: 'car_price', title: __('Car_price'),operate: false},
                        {field: 'dk_prrice', title: __('Dk_prrice'),operate: false},
                        {field: 'beneficiary', title: __('Beneficiary'),operate: false},
                        {field: 'create_time', title: __('Create_time'), operate:'RANGE', addclass:'datetimerange', formatter: Table.api.formatter.datetime,operate: false},
                        {field: 'out_trade_no', title: __('Out_trade_no'),operate: false},
                        {field: 'pay_status', title: __('Pay_status'),operate: false},
                        {field: 'pay_time', title: __('Pay_time'), operate:'RANGE', addclass:'datetimerange', formatter: Table.api.formatter.datetime,operate: false},
                        // {field: 'recipient_name', title: __('Recipient_name'),operate: false},
                     
                    ]
                ],exportOptions: { 
                  mso:{  
                    onMsoNumberFormat: function (cell, row, col) {
                        return !isNaN($(cell).text())?'\\@':'';
                    },
                  }
                },
            });

            // 为表格绑定事件
            Table.api.bindevent(table);
        },
        add: function () {
            Controller.api.bindevent();
        },
        edit: function () {
            Controller.api.bindevent();
        },
        api: {
            bindevent: function () {
                Form.api.bindevent($("form[role=form]"));
            }
        }
    };
    return Controller;
});